package cn.codergege.myspider.component;


import org.apache.http.NameValuePair;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 请求
 * 封装了 url, GET/POST, params... 相当于 HttpGet/HttpPost
 * // TODO: 2019-05-30 connectTimeOut , 配置文件中获取? readTimeOut?
 */
// TODO: 2019-05-30 @Getter @Setter
public class Request<T> {
    private String url; // 应该是不带参数的完整的 url, TODO: url 还需要处理?
    private String method = "GET"; // 默认 GET 请求
    private Map<String, String> headers = new HashMap<>(); // 请求头
    private Map<String, String> cookies = new HashMap<>(); // cookies
    private String contentType = "text/html; charset=UTF-8";
    private String charset = "UTF-8";
    private List<NameValuePair> nvps;
    private Parser<T> parser; // TODO: 2019-05-31 有没有必要呢?

    public Request(String url, Parser<T> parser) {
        this(url, parser, null);
    }

    public Request(String url, Parser<T> parser, List<NameValuePair> nvps) {
        this.parser = parser;
        this.nvps = nvps;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public Map<String, String> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, String> headers) {
        this.headers = headers;
    }

    public Map<String, String> getCookies() {
        return cookies;
    }

    public void setCookies(Map<String, String> cookies) {
        this.cookies = cookies;
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    public String getCharset() {
        return charset;
    }

    public void setCharset(String charset) {
        this.charset = charset;
    }

    public List<org.apache.http.NameValuePair> getNvps() {
        return nvps;
    }

    public void setNvps(List<NameValuePair> nvps) {
        this.nvps = nvps;
    }
}
